/**
 * name:        帮助中心左边菜单
 * author:      wuwq & lyj
 * Time:        18/01/31
 * Copyright:   chinadangmai.com
 */

$(function(){
    var w_h=$(window).height();
    $('.mod_backstage').css('min-height',(w_h-422)+'px');
    // 获取左侧菜单
    helpCenterCategoryList();       // 加载左侧菜单
    // 获取左侧菜单
    var url = new_url+'shop/article/getHelpCenterCategoryList';
    getHelpCenterCategoryList(url);     // 获取左侧菜单
});
// 加载左侧菜单
function helpCenterCategoryList(){
    var nav = '';
    var scri = '';
    var scri2 = '';

    nav += '<h4 class="nav_tit">常见问题</h4>';
    nav += '<a href="help.html" class="help_home">首页</a>';
    nav += '<ul class="help_menu">';
    nav += '</ul>';
    
    scri += '<script id="helpNavTpl" type="text/html">';
    scri += '{{ for( var i=0; i < helpNavList.length; i++) { }}';
    scri += '<li class="help_list">';
    scri += '<a href="javascript:;" class="mene_list">{{=helpNavList[i].name}}</a>';
    scri += '<ul class="help_submenu" id="h{{=helpNavList[i].index}}">';
    scri += '</ul>';
    scri += '</li>';
    scri += '{{ } }}';
    scri += '</script>';
    
    scri2 += '<script id="helpSubMenuTpl" type="text/html">';
    scri2 += '{{ for( var i=0; i < helpSubList.length; i++) { }}';
    scri2 += '<li class="submenu_list" data-id="{{=helpSubList[i].articleClassId}}"><a href="help_detail.html?Id={{=helpSubList[i].articleClassId}}">{{=helpSubList[i].name}}</a></li>';
    scri2 += '{{ } }}';
    scri2 += '</script>';

    $('.help_nav').append(nav);
    $('body').append(scri);
    $('body').append(scri2);
}
// 获取左侧菜单
function getHelpCenterCategoryList(url){
    $.ajax({
        type:'post',
        url:url,
        dataType:'json',
        success:function(e){   
            if(e.code == '0'){
                var helpNavTpl = $("#helpNavTpl").html();
                for(var i=0;i<e.data.length;i++){
                    var helpNavCont=template(
                        helpNavTpl, {
                            helpNavList: [{
                                index:i+1,
                                articleClassId:e.data[i].articleClassId,        // 一级文章分类id
                                name:e.data[i].name
                            }]
                        }
                    );
                    $('.help_menu').append(helpNavCont);  
                }
                var helpSubMenuTpl = $("#helpSubMenuTpl").html();
                for(var i=0;i<e.data.length;i++){
                    for(var j=0;j<e.data[i].childList.length;j++){
                        var helpSubMenuCont=template(
                            helpSubMenuTpl, {
                                helpSubList: [{
                                    articleClassId:e.data[i].childList[j].articleClassId,       // 二级文章分类id
                                    name:e.data[i].childList[j].name
                                }]
                            }
                        );
                        var s = '#h'+(i+1);
                        $(s).append(helpSubMenuCont); 
                    } 
                }
            }
        }
    });
}

